<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
    <%@ page import="no.ntnu.tdt4237.*" %>
    <%@page import="no.ntnu.tdt4237.helperactions.*"%>
    <%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<tags:header title=" - Activation"></tags:header>

<script language="JavaScript" type="text/JavaScript">
	function redirect() {
		var loc = location.href.split(':');
		if (loc[0]=='http') {
			location.href='https:'+loc[1].substring(0,loc[1].length-1)+":8453";
		}
	}
</script>

<body onload="redirect()">

<%
boolean activationSuccess = false;


if(Database.genCode(request.getParameter("Brukernavn")).equals(request.getParameter("Code"))){
	activationSuccess = true;
}



if (activationSuccess) {
	Database.validateUser(request.getParameter("Brukernavn"));
	%>
	<tags:message message="Your account is validated, you can now log in!"></tags:message>
	<span><a href="login.jsp">Log in!</a></span>
	<%
}
else
{
	%>
		<div class="LoginBox">
		<form action="Activation.jsp" method="post">
			<span>UserName:</span><input type="text" name="Brukernavn"></input><br/>
			<span>Activation Code:</span><input type="text" name="Code"></input><br/>
			<input type="submit" value="Activate"></input>
		</form>
		</div>
	<%
}
%>


</body>
</html>